import React from "react";
import "./login.less";
import img1 from "../../assets/img/ico.png";
import { message, Button, Space } from "antd";
import $ from "jquery";

import { subLogin } from "../../api/index.js";
// 登陆
export default class Login extends React.Component {
  constructor(props) {
    super(props);
  }

  subLogin = (e) => {
    e.preventDefault();
    this.props.history.push("/");
    message.success("测试登陆成功");


    return
    
    let nameele = document.querySelector("#username").value.trim();
    let passwordele = document.querySelector("#password").value.trim();
    if (nameele.length > 4 && nameele.length < 12) {
      if (passwordele.length > 4 && passwordele.length < 12) {
        //通过验证

        let data = {
          username: nameele,
          password: passwordele,
        };
        subLogin(data).then((res) => {
          // console.log(res)
          if (res.status == 0) {
            //保存到本地
            let userdata = JSON.stringify(res.data);
            sessionStorage.setItem("userdata", userdata);
            this.props.history.push("/");
            message.success("登陆成功");
          }
        });
      } else {
        message.error("密码长度在4~14");
      }
    } else {
      message.error("用户名长度在4~14");
    }
  };

  render() {
    return (
      <div className="login">
        <div className="login-header">
          <img src={img1} alt="" />
          <h1>后台管理登陆页面</h1>
        </div>
        <div className="logn-content">
          <div className="login-center">
            <h2>LOGIN</h2>

            <form action="">
              <input
                id="username"
                type="text"
                name="username"
                placeholder="uername"
              />
              <input
                id="password"
                type="password"
                name="password"
                placeholder="password"
              />
              <button type="submit" onClick={this.subLogin}>
                <strong>submit</strong>
              </button>
            </form>
          </div>
        </div>
      </div>
    );
  }
}
